#include "sublogic.h"

void test_read_txt()
{
    // 打开文件
    FILE* fp = fopen(USER_DATABASE,"r");
    if(fp == NULL)
    {
        perror("USER_DATABASE fopen error!");
        exit(0);
    }

    char userinfo[UINFO_LENGTH];    // 保存一条用户信息
    char temp_acc[USER_ACCOUNT];
    char temp_pwd[USER_ACCOUNT];
    char ingroup[1];
    int a;

    // 遍历数据库文件，对比该帐号是否正确
    while(Fgets(userinfo,UINFO_LENGTH,fp) != NULL)
    {

//        sscanf (userinfo,"%s\t%s\t%s\n",temp_acc,temp_pwd,ingroup);
        fscanf(fp, "%s %s %s\n", temp_acc, temp_pwd, ingroup);
        printf("userinfo: %s\t%s\t%s\n",temp_acc,temp_pwd,ingroup);
    }
}



void test_write_txt()
{
    // 打开文件
    FILE* fp = fopen(USER_DATABASE,"a+");
    if(fp == NULL)
    {
        perror("fopen error!");
        exit(0);
    }

    fprintf(fp,"%s\t%s\t%s\n","wujie","123","1");

    fclose(fp);
}
